const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isNOne:false,
    iswriteList:true,
    isloupanList:false,
    iszixunList:false,
    TabCur: 0,
    scrollLeft: 0,
    tabList:[
      {
        'id':0,
        'name':'写一写'  
      },
      {
        'id': 1,
        'name': '楼盘'
      },
      {
        'id': 2,
        'name': '资讯'
      },
    ]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var vm = this;
    var opid = wx.getStorageSync('user').openid;
    var url = "get_user_collect/open_id/" + opid + "/type/0";
    app.core('get', url, {
    }, (res) => {
        //写一写
        if (res.data.length > 0) {
          vm.setData({
            writeList: res.data,
            isNOne: false
          });
        } else {
          vm.setData({
            isNOne: true
          });
        }
      
      },
      (err) => {
        console.log(err)
      }
    )

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },
  tabSelect(e) {
    var tabId = e.currentTarget.dataset.id;
    if (tabId == 0) {
      this.setData({
        iswriteList: true,
        isloupanList: false,
        iszixunList: false,
      })
    } else if (tabId == 1) {
      this.setData({
        iswriteList: false,
        isloupanList: true,
        iszixunList: false,
      });
    } else {
      this.setData({
        iswriteList: false,
        isloupanList: false,
        iszixunList: true,
      })
    };

    var vm = this;
    var open_id = wx.getStorageSync('user').openid;
    var typeof_s = e.currentTarget.dataset.id;
    var url = "get_user_collect/open_id/" + open_id + "/type/" + typeof_s ;
    app.core('get', url, {
    }, (res) => {
      if (res.status == 'write'){
        //写一写
        if (res.data.length>0){
          vm.setData({
            writeList:res.data,
             isNOne: false
          });
        }else{
          vm.setData({
            isNOne: true
          });
        }
      }else if (res.status == 'loupan'){
        //楼盘
        if (res.data.length > 0) {
          vm.setData({
            loupanList: res.data,
            isNOne: false
          });
        } else {
          vm.setData({
            isNOne: true
          });
        }
      }else{
        //资讯
        if (res.data.length > 0) {
          vm.setData({
            zixunList: res.data,
            isNOne: false
          });
        } else {
          vm.setData({
            isNOne: true
          });
        }
      }

    },
      (err) => {
        console.log(err)
      }
    )

    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  },
})